from flask import Blueprint, request, url_for, session, redirect

admin_blu = Blueprint("admin", __name__,url_prefix='/admin')

# 重新导入views是因为注册的时候用views蓝图
from . import views

@admin_blu.before_request
def before_request():
    '''
    请求钩子
    :return:
    '''
    if not request.url.endswith(url_for('admin.admin_login')):
        user_id = session.get('user_id')
        is_admin = session.get('is_admin',False)
        if not user_id and not is_admin:
            return redirect('/')